import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.httpclient

from tornado.options import define, options

define("port", default=8000, help="run on the given port", type=int)


class IndexHandler(tornado.web.RequestHandler):

    def get(self):
        client = tornado.httpclient.HTTPClient()
        response = client.fetch("http://www.cnblogs.com/lianzhilei")  # 访问url，并返回response
        self.write("""
                <div style="text-align: center">
                    <div style="font-size: 72px">Time Cost</div>
                    <div style="font-size: 72px">%s</div>
                </div>""" % (response.request_time))  # 访问开销


if __name__ == "__main__":
    tornado.options.parse_command_line()
    app = tornado.web.Application(handlers=[(r"/", IndexHandler)])
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()